home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 109 / EnigmaAmiga109CD.iso / dalla rivista / host contacted / imengv3.41p2.lha / ImEngV3.41p2 / Extra / ARexx / IndexMultiply.rexx < prev    next >
OS/2 REXX Batch file  |  1997-01-06  |  2KB  |  65 lines

  1. /*
  2. ** $VER: IndexMultiply.rexx 1.03 (4/1 Stockholm/Sweden)
  3. ** Copyright © 1997 by Patrik M Nydensten 
  4. **
  5. ** Clones a single file with an index number.
  6. ** The new name will be the old basename with a new index number ranging
  7. ** upwards or downwards. Positvie clone number makes the new indexes range
  8. ** upwards while negative makes them range downwards.
  9. **
  10. ** Usage: <number_of_clones> <indexed file>
  11. */
  12.  
  13. options results
  14.  
  15. parse arg number files
  16. if pos('"',files) = 0 then parse var files file1 .
  17. else parse var files '"'file1'"'
  18.  
  19. if ~datatype(number,'N') then errorx('Error: Bad clone number.')
  20.  
  21. fix = strip(get_ext(file1)) ; lix = fix + number
  22. if ((~datatype(fix,'N'))|(~datatype(lix,'N'))) then errorx('Error: Bad index number in file name.')
  23. fi = min(fix,lix) ; li = max(fix,lix)
  24.  
  25. if ~exists(file1) then errorx('Error: Could not locate file "'file1'"')
  26.  
  27. do i = fi to li
  28.   if i = fix then iterate
  29.   
  30.   if i < 1 then do
  31.     say 'Error: Index goes below 1.'
  32.     iterate
  33.   end
  34.   
  35.   old_file = file1
  36.   new_file = get_base(file1)'.'right(i,4,'0')
  37.  
  38.   if ~exists(new_file) then do
  39.     address 'COMMAND' 'copy' '"'old_file'"' '"'new_file'"'
  40.   end
  41.   else say 'Error: File already exists, "'new_file'".'
  42. end
  43.  
  44. exit
  45.  
  46. /* --[ proc ]--------------------------- */
  47.  
  48. errorx:
  49.   parse arg text
  50.   say text
  51.   exit 5
  52. return 0
  53.  
  54. get_ext:
  55.   parse arg get_ext_in
  56.   if lastpos('.',get_ext_in) ~= 0 then get_ext_back = substr(get_ext_in,1+lastpos('.',get_ext_in))
  57.   else get_ext_back = ''
  58. return get_ext_back
  59.  
  60. get_base:
  61.   parse arg get_base_in
  62.   if lastpos('.',get_base_in) ~= 0 then get_base_back = substr(get_base_in,1,lastpos('.',get_base_in)-1)
  63.   else get_base_back = get_base_in
  64. return get_base_back
  65.